package com.example.warehousesystem_manager_api.controller;

import com.example.warehousesystem_common.pojo.vo.SupplierListVO;
import com.example.warehousesystem_common.service.ISupplierService;
import com.example.warehousesystem_common.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 处理Supplier相关请求的控制器类
 * @author heshijiang
 * @version 0.0.1
 */
@RestController
@Slf4j
@RequestMapping("/suppliers")
@Validated
public class SupplierController {

    @DubboReference
    private ISupplierService supplierService;

    // http://localhost:9003/suppliers
    @GetMapping("")
    @ApiOperation("查询供应商列表")
    @ApiOperationSupport(order = 100)
    public JsonResult<List<SupplierListVO>> list() {
        log.debug("开始处理【查询供应商列表】的业务，无参数");
        List<SupplierListVO> list = supplierService.list();
        return JsonResult.ok(list);
    }
    // http://localhost:9003/suppliers/9527/enable
    @ApiOperation("开启供应商")
    @ApiOperationSupport(order = 110)
    @ApiImplicitParam(name = "id", value = "类别id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/enable")
    public JsonResult setEnable(@PathVariable Long id) {
        log.debug("开始处理【启用供应商】的请求，参数：{}", id);
        supplierService.setEnable(id);
        return JsonResult.ok();
    }

    // http://localhost:9003/suppliers/9527/disable
    @ApiOperation("禁用供应商")
    @ApiOperationSupport(order = 120)
    @ApiImplicitParam(name = "id", value = "类别id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/disable")
    public JsonResult setDisable(@PathVariable Long id) {
        log.debug("开始处理【禁用供应商】的请求，参数：{}", id);
        supplierService.setDisable(id);
        return JsonResult.ok();
    }

}
